package fr.cnam.ratpProject.client.activities.searchStation;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.ui.client.widget.buttonbar.SearchButton;

import fr.cnam.ratpProject.client.activities.searchStation.SearchStation.SearchStationView;
import fr.cnam.ratpProject.client.utils.RatpCommand;
import fr.cnam.ratpProject.sharedDatas.Station;

public class SearchStationViewImpl extends Composite implements SearchStationView {

	private VerticalPanel main = new VerticalPanel();
	private RatpCommand<String> addCommand;

	private SuggestBox txtSearch = null;
	
	private MultiWordSuggestOracle suggest = new MultiWordSuggestOracle(); 
	
	public SearchStationViewImpl()
	{
		initWidget(main);
		
		Label titre = new Label("Recherche d'une station");
		//TODO css titre
		
		main.add(titre);
		
		HorizontalPanel hp = new HorizontalPanel();
		
		txtSearch = new SuggestBox(suggest);
		
		
		
		SearchButton btnSearch = new SearchButton();
		btnSearch.addTapHandler(new TapHandler() {
			
			@Override
			public void onTap(TapEvent event) {
				if(addCommand !=null)
					addCommand.execute(txtSearch.getValue());
			}
		});
		
		hp.add(btnSearch);
		btnSearch.setSize("2Opx", "20px");
		hp.add(txtSearch);
		
		
		
		
		
		main.add(hp);
		
		
	}
	
	@Override
	public void setAddCommand(RatpCommand<String> command) {
		this.addCommand = command;
		
	}
	

	@Override
	public void setSuggestStations(ArrayList<Station> result) {
		suggest.clear();
		if(result !=null)
		{
			for(Station station:result)
			{
				suggest.add(station.getName());
			}
				
		}
	}

	@Override
	public void buildAdClass() {
		main.clear();
		main.add(new Label("Lignes les plus perturbées depuis le 1er Janvier 2013"));
		FlexTable flex = new FlexTable();
		int row = -1;
		flex.setWidget(++row, 0, new Label("Ligne 4"));
		flex.setWidget(row, 1, new Label("50%"));
		flex.setWidget(++row, 0, new Label("Ligne 1"));
		flex.setWidget(row, 1, new Label("48%"));
		flex.setWidget(++row, 0, new Label("Ligne 2"));
		flex.setWidget(row, 1, new Label("32%"));
		flex.setWidget(++row, 0, new Label("Ligne 7"));
		flex.setWidget(row, 1, new Label("22%"));
		flex.setWidget(++row, 0, new Label("Ligne 8"));
		flex.setWidget(row, 1, new Label("18%"));
		flex.setWidget(++row, 0, new Label("Ligne 10"));
		flex.setWidget(row, 1, new Label("17%"));
		
		main.add(flex);
	}


}
